/*
 * Created on 2005-5-19
 */
package org.nanhill.commons.model;

import java.util.Random;

/**
 * @author alin
 */
public class StringGenerator {
	public static final char[] DEFAULT_SEEDS = { '0', '1', '2', '3', '4', '5',
			'6', '7', '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
			'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
			'V', 'W', 'X', 'Y', 'Z' };

	private char[] seeds;

	private Random rand = new Random();

	public StringGenerator(char[] seeds) {
		this.seeds = seeds;
	}

	public StringGenerator() {
		this(DEFAULT_SEEDS);
	}

	public String nextSerial(int len) {
		char[] serial = new char[len];
		for (int i = 0; i < len; i++) {
			int seedIndex = rand.nextInt(seeds.length);
			serial[i] = seeds[seedIndex];
		}
		return new String(serial);
	}
}
